package study

import (
	"fmt"
	"os"
	"time"
)

type PathError struct {
	path       string
	op         string
	createTime string
	message    string
}

func (p *PathError) Error() string {
	return fmt.Sprintf("path:%v, op:%v, createTime:%v, message:%v", p.path, p.op, p.createTime, p.message)
}

func Open(filename string) error {
	file, err := os.Open(filename)
	if err != nil {
		return &PathError{
			path:       filename,
			op:         "read",
			createTime: fmt.Sprintf("%v", time.Now()),
			message:    err.Error(),
		}
	}
	defer file.Close()
	return nil
}

func main() {
	err := Open("/users/weimingwei/Desktop/go/src/test.txt")
	switch v := err.(type) {
	case *PathError:
		fmt.Println("get path error", v)
	default:

	}

	/*c*/

}
